package com.atguigu.gulimall.coupon.controller;

import java.util.Arrays;
import java.util.Map;

//import com.atguigu.gulimall.coupon.config.CartProperties;
//import com.atguigu.gulimall.coupon.config.CartProperties;
import com.atguigu.gulimall.coupon.config.CartProperties;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.atguigu.gulimall.coupon.entity.CouponEntity;
import com.atguigu.gulimall.coupon.service.CouponService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * 优惠券信息
 *
 * @author jieGe
 * @email jieGe@gmail.com
 * @date 2025-04-23 11:33:58
 */
@RequiredArgsConstructor //这个注解是lombok提供的，可以自动生成构造函数，并注入所需的依赖
@RestController //这个注解表示这是一个控制器类，会自动扫描到这个类，并生成相应的RESTful API接口
@RequestMapping("coupon/coupon")
public class CouponController   {
    @Autowired
    private CouponService couponService;

   private final CartProperties cartProperties;

//    @Value("${coupon.user.age}")
//    private Integer age;
//    @Value("${coupon.user.name}")
//    private String name;

    /**
     * @return
     */

    @GetMapping("/test")
    public R test(){
        System.out.println(cartProperties.getName());
        System.out.println(cartProperties.getAge());
        return R.ok().put("name", cartProperties.getName()).put("age", cartProperties.getAge());
    }



    //查询会员的所有优惠劵的代码
    @RequestMapping("/member/list")
    public R membercoupons(){
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("满100减10");
        return R.ok().put("coupons",Arrays.asList(couponEntity));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
